package com.cuntian.rocketmq.consumer;


import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;
import com.alibaba.fastjson.JSON;

@Slf4j
@Component
@RocketMQMessageListener(
        topic = "cuntian-study-rocketmq",
        consumerGroup = "cuntian-springboot-rocketmq-message-ext"
)
public class RocketMQConsumerMessageExt  implements RocketMQListener<MessageExt> {

    @Override
    public void onMessage(MessageExt message) {

        String value = new String(message.getBody());
        log.info("consume message in RocketMQConsumerMessageExt: [{}], [{}]",
                message.getKeys(), value);
        // 会慢一些
        log.info("MessageExt: [{}]", JSON.toJSONString(message));
    }
}
